package cn.huiyunche.base.service.interfaces.impl;

import cn.huiyunche.base.service.interfaces.BCityFactorService;
import cn.huiyunche.base.service.mappers.BCityFactorMapper;
import cn.huiyunche.base.service.model.BCityFactor;
import cn.huiyunche.base.service.model.BCityFactorExample;
import cn.huiyunche.tools.basic.exceptions.BusinessException;
import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class BCityFactorServiceImpl implements BCityFactorService {

    private static final Logger LOGGER = LoggerFactory.getLogger(BCityFactorServiceImpl.class);

    @Autowired
    private BCityFactorMapper bCityFactorMapper;

    @Override
    public BigDecimal getVlaueByFeeCode(String feeCode) {
        LOGGER.info("getVlaueByFeeCode param : {}", feeCode);
        if (null == feeCode) {
            throw new BusinessException("费用编号不能为空！");
        }
        BCityFactorExample example = new BCityFactorExample();
        example.createCriteria().andFeeCodeEqualTo(feeCode);
        List<BCityFactor> list = bCityFactorMapper.selectByExample(example);
        if (CollectionUtils.isEmpty(list)) {
            throw new BusinessException("获取费用因子信息失败！");
        }
        return list.get(0).getValue();
    }

}
